using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace ERPStore.Cart.Repositories.Mapping
{
	public class CartItemMap : EntityTypeConfiguration<Datas.CartItem>
	{
		public CartItemMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

            this.Property(e => e.Id)
                .IsRequired()
                .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity);

			// Properties
			this.Property(t => t.RevisionId)
				.IsRequired()
				.IsFixedLength()
                .IsConcurrencyToken()
                .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)
				.HasMaxLength(8);
				
			this.Property(t => t.InventoryTimeStateId).IsOptional();

			this.HasRequired(i => i.Cart)
				.WithMany(i => i.Items)
				.HasForeignKey(i => i.CartId);

			ToTable("CartItem");
		}
	}
}

